/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import javax.swing.plaf.TableHeaderUI;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>Project: javase - T11
 * <p>Powered by webrx On 2021-12-24 17:38:06
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T11 {
    Lock l = new ReentrantLock(true);

    void test() {
        String n = Thread.currentThread().getName();
        System.out.println(n + "线程启动");
        for (int i = 0; i < 5; i++) {
            l.lock();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(n + ",hello.");
            l.unlock();
        }

    }

    public static void main(String[] args) {
        T11 t = new T11();
        new Thread(t::test, "T1").start();
        new Thread(t::test, "T3").start();
        new Thread(t::test, "T2").start();
    }
}
